import  java.util.Scanner;
public class GuessNumber {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //1.生成
        String afain;
      do {
        int answer = (int) (Math.random() * 100 + 1);
        //限制猜测
        int chances=7;


        //2接受
        while (chances>0) {
            System.out.println("请输入:"+"你还有"+chances+"次机会,输入“-1”可结束游戏");
            int guess;
            try {
                 guess = scan.nextInt();
            }catch (Exception e){
                System.out.println("请输入合法数字");
                scan.next();
                continue;
            }
            //3.比较
            if (guess==-1) {
                System.out.println("重新开始");
                break;
            }else if(guess>answer){

                System.out.println("大");
            } else if (guess < answer) {
                System.out.println("小");
            } else {
                System.out.println("对");
                break;
            }
            //4.猜一次比一次

chances=chances-1;
        }
        if (chances<=0){
            System.out.println("你没机会了");
        }
        //实现可以玩多轮
        System.out.println("在玩一次？（Y/N）");
         afain=scan.next();

    }
    while (  afain.equalsIgnoreCase("Y"));
}}